Skip to content

Fix Find response ranges for paginated and empty results - #237

Merged
matidau merged 1 commit into
Z-Hub:developfrom
rfc4711:codex/find-response-ranges
Nov 26, 2026
Merged

matidau merged 1 commit into
Z-Hub:developfrom
rfc4711:codex/find-response-ranges

Conversation

@rfc4711

@rfc4711 rfc4711 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Released under the GNU Affero General Public License (AGPL), version 3.

What does this implement/fix?

Find currently encodes its response Range as 0-<searchtotal>. That reports the estimated total rather than the returned page and makes the end index one too large even for an initial page. For example, ten returned messages produce 0-10 instead of 0-9.

Use the backend-provided range start, falling back to the requested start, and calculate the end from the number of returned rows. Omit the optional Range element when no rows are returned. Total remains unchanged.

The Find Range specification defines zero-based inclusive indexes and describes the response range as the entries actually returned.

Related issues

Related to #147, but independent of its folder-ID/Fetch discussion. This PR leaves request parsing, folder mapping, Fetch arguments and advertised protocol versions unchanged.

Validation

Added a self-contained WBXML regression test:

php tests/find-response-ranges.php

Eight cases fail on unmodified develop at c51d2682d8c0d0f74faed3c23da81dd1cb2f2ec3 and pass with this change: initial and single-result pages, nonzero offsets, a partial last page, an empty next page, no matches, missing provider range metadata and an omitted request range.

Tested with PHP 8.4 CLI on Debian 13 using mock search/device/backend objects. No real mailbox, SQL connection or production configuration is used. The tests also pass when combined with the separately proposed preview-safety fix. Upstream CI has not run yet.

A related stable-version backport was exercised with Apple Mail on an iPhone, including searching outside a one-week sync window and opening results. That device test was not performed against this development branch; validation of this exact branch is the regression test above.

@matidau
matidau merged commit 2b79928 into Z-Hub:develop Nov 26, 2026
3 checks passed
@matidau

matidau commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the PR, I was initially concerned about adding in the tests folder when we don't have a structured way of testing or running them as CI jobs. But will add this in for now and change it up later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants